package com.ysh.webflux.dao;

import com.ysh.webflux.pojo.User;
import org.springframework.data.r2dbc.repository.Modifying;
import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/**
 * 袁胜虎 on 2022/9/22 22:35
 */
@Repository//让spring创建当前的接口的对象,是一个代理对象
public interface UserRepository extends ReactiveCrudRepository<User,Long> {
        Flux<User> findAllByNameLike(String name);

        Mono<User> findUserByNameEquals(String name);

        Mono<Integer> deleteUserByNameEquals(String name);
        @Modifying//代表是一个修改的语句
        @Query("UPDATE `users` set name=:#{#user.name},  age=:#{#user.age},address=:#{#user.address},birth_day=:#{#user.birthDay} WHERE uid=:#{#user.uid}")
        Mono<Integer> updateUserById(@Param("user") User user);

        Mono<User> findFirstByNameLike(String name);
}
